<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
    

<head><meta name="generator" content="Hexo 3.8.0">
    <meta charset="utf-8">
    <meta name="keywords" content="R常用命令, 炫杉">
    <meta name="description" content="R语言常用命令记录


?&amp;#39;mean&amp;#39;可以看介绍
apropos(&amp;quot;mea&amp;quot;)搜包含mea字符的方法

运算符数学运算：+，-，*，/，^，%%。(加，减，乘，除，乘方，求余。)
比较运算：

，&amp;lt;">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <title>R常用命令 | 炫杉</title>
    <link rel="icon" type="image/png" href="/favicon.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/css/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">

    <script src="/libs/jquery/jquery-2.2.0.min.js"></script>
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css">
<link rel="stylesheet" href="/css/prism-line-numbers.css" type="text/css"></head>

</head>

<body>

<header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="container">
            <div class="nav-wrapper">
                <div class="brand-logo">
                    <a href="/" class="waves-effect waves-light">
                        
                        <img src="/medias/logo.png" class="logo-img hide-on-small-only">
                        
                        <span class="logo-span">炫杉</span>
                    </a>
                </div>
                <a href="#" data-activates="mobile-nav" class="button-collapse"><i class="fa fa-navicon"></i></a>
<ul class="right">
    
    <li class="hide-on-med-and-down">
        <a href="/" class="waves-effect waves-light">
            
            <i class="fa fa-home"></i>
            
            <span>Index</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/tags" class="waves-effect waves-light">
            
            <i class="fa fa-tags"></i>
            
            <span>Tags</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/categories" class="waves-effect waves-light">
            
            <i class="fa fa-bookmark"></i>
            
            <span>Categories</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/archives" class="waves-effect waves-light">
            
            <i class="fa fa-archive"></i>
            
            <span>Archives</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/about" class="waves-effect waves-light">
            
            <i class="fa fa-user-circle-o"></i>
            
            <span>About</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="https://oo1.win" class="waves-effect waves-light">
            
            <i class="fa fa-star"></i>
            
            <span>Bookmark</span>
        </a>
    </li>
    
    <li>
        <a id="toggleSearch" class="waves-effect waves-light">
            <i id="searchIcon" class="mdi-action-search"></i>
        </a>
    </li>

</ul>

<div class="side-nav" id="mobile-nav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">炫杉</div>
        <div class="logo-desc">
            
            提着鸟笼的老头站在一旁拍我肩膀 我猜他想的应该和我一样
            
        </div>
    </div>

    <ul class="menu-list mobile-menu-list">
        
        <li>
            <a href="/" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-home"></i>
                
                Index
            </a>
        </li>
        
        <li>
            <a href="/tags" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-tags"></i>
                
                Tags
            </a>
        </li>
        
        <li>
            <a href="/categories" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-bookmark"></i>
                
                Categories
            </a>
        </li>
        
        <li>
            <a href="/archives" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-archive"></i>
                
                Archives
            </a>
        </li>
        
        <li>
            <a href="/about" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-user-circle-o"></i>
                
                About
            </a>
        </li>
        
        <li>
            <a href="https://oo1.win" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-star"></i>
                
                Bookmark
            </a>
        </li>
        
        
    </ul>

    <div class="social-link"><a href="https://github.com/ixsim" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
    <i class="fa fa-github"></i>
</a>

<a href="mailto:chenjiayin1990@163.com" class="tooltipped" target="_blank" data-tooltip="邮件:chinalixs@qq.com" data-position="top" data-delay="50">
    <i class="fa fa-envelope-open"></i>
</a>

<a href="http://wpa.qq.com/msgrd?v=3&uin=6956820&site=qq&menu=yes" class="tooltipped" data-tooltip="QQ: 6956820" data-position="top" data-delay="50">
    <i class="fa fa-qq"></i>
</a>
</div>
</div>

            </div>
        </div>

        
    </nav>
</header>



<div class="bg-cover post-cover" style="background-image: url('/medias/featureimages/1.jpg')">
    <div class="container">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <div class="description center-align post-title">
                        R常用命令
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>



<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1,
    #articleContent h2,
    #articleContent h3,
    #articleContent h4,
    #articleContent h5,
    #articleContent h6 {
        padding-top: 76px;
        margin-top: -76px;
    }

    #articleContent h1 {
        line-height: 3.5rem;
    }

    #articleContent h2 {
        line-height: 3.2rem;
    }

    #articleContent h3 {
        line-height: 2.8rem;
    }

    #articleContent h4 {
        line-height: 2.5rem;
    }

    #articleContent h5 {
        line-height: 2.2rem;
    }

    #articleContent h6 {
        line-height: 1.9rem;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        margin: 35px 0 15px 0;
        padding-left: 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #toc-content .is-active-link::before {
        background-color: #42b983;
    }
</style>
<div class="row">
    <div class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            
            <div class="article-tag">
                
                <a href="/tags/Note/" target="_blank">
                    <span class="chip bg-color">Note</span>
                </a>
                
                <a href="/tags/Data-Analysis/" target="_blank">
                    <span class="chip bg-color">Data Analysis</span>
                </a>
                
                <a href="/tags/R/" target="_blank">
                    <span class="chip bg-color">R</span>
                </a>
                
            </div>
            
            <div class="post-info">
                
                <span class="post-cate">
                    <i class="fa fa-bookmark fa-fw icon-category"></i>
                    
                    <a href="/categories/Others/" class="post-category" target="_blank">
                        Others
                    </a>
                    
                </span>
                

                <span class="post-date">
                    <i class="fa fa-clock-o fa-fw"></i>2018-03-31
                </span>
            </div>
        </div>
        <hr>
        <div class="card-content article-card-content">
            <div id="articleContent">
                <p>R语言常用命令记录</p>
<a id="more"></a>
<ul>
<li><code>?&#39;mean&#39;</code>可以看介绍</li>
<li><code>apropos(&quot;mea&quot;)</code>搜包含mea字符的方法</li>
</ul>
<h1 id="运算符"><a href="#运算符" class="headerlink" title="运算符"></a>运算符</h1><p>数学运算：<br>+，-，*，/，^，%%。(加，减，乘，除，乘方，求余。)</p>
<p>比较运算：</p>
<blockquote>
<p>，&lt;，&gt;=，&lt;=，==，!=。(大于，小于，大于等于，小于等于，等于，不等于。)</p>
</blockquote>
<p>逻辑运算：<br>&amp;，|，!。(与，或，非。)</p>
<ul>
<li>初始基本操作</li>
</ul>
<hr>
<blockquote>
<p>getwd()</p>
<ul>
<li>获取工作目录。</li>
</ul>
</blockquote>
<blockquote>
<p>setwd(“F:/R/myfun”)</p>
<ul>
<li>设定工作目录为F:/R/myfun。</li>
</ul>
</blockquote>
<blockquote>
<p>help(com)<br>?com</p>
<ul>
<li>获得对命令com的说明。</li>
</ul>
</blockquote>
<blockquote>
<p>example(com)</p>
<ul>
<li>命令com的使用实例。</li>
</ul>
</blockquote>
<blockquote>
<p>args(com)</p>
<ul>
<li>查看命令com的变量格式。</li>
</ul>
</blockquote>
<blockquote>
<p>library()</p>
<ul>
<li>列出已安装的包。</li>
</ul>
</blockquote>
<blockquote>
<p>library(AER)  -  或用<br>require(AER)</p>
<ul>
<li>载入包AER。</li>
</ul>
</blockquote>
<blockquote>
<p>library(help = AER)</p>
<ul>
<li>获取包AER的信息。</li>
</ul>
</blockquote>
<blockquote>
<p>detach(package:AER)</p>
<ul>
<li>去除载入的包AER。</li>
</ul>
</blockquote>
<blockquote>
<p>search()</p>
<ul>
<li>列出已载入的包。</li>
</ul>
</blockquote>
<blockquote>
<p>data()</p>
<ul>
<li>列出已载入的包中的所有数据集。</li>
</ul>
</blockquote>
<blockquote>
<p>data(package = .packages(all.available = TRUE))</p>
<ul>
<li>列出已安装的包中的所有数据集。</li>
</ul>
</blockquote>
<blockquote>
<p>try(data(package = “AER”) )</p>
<ul>
<li>列出包AER里的所有数据集。</li>
</ul>
</blockquote>
<blockquote>
<p>data(Affairs, “BankWages”)</p>
<ul>
<li>读入数据集Affairs和BankWages(这些数据集需已在data()中列出)。</li>
</ul>
</blockquote>
<blockquote>
<p>help(Affairs)</p>
<ul>
<li>获取数据集Affairs的信息。</li>
</ul>
</blockquote>
<blockquote>
<p>attach(Affairs)</p>
<ul>
<li>贴上数据集Affairs，其作用是可以直接对数据集里的变量进行操作。</li>
</ul>
</blockquote>
<blockquote>
<p>detach(Affairs)</p>
<ul>
<li>上述操作的逆操作。</li>
</ul>
</blockquote>
<hr>
<h1 id="对一般对象的基本操作"><a href="#对一般对象的基本操作" class="headerlink" title="对一般对象的基本操作"></a>对一般对象的基本操作</h1><blockquote>
<p>objects()<br>ls()</p>
<ul>
<li>列出所有对象。</li>
</ul>
</blockquote>
<blockquote>
<p>mode(x)</p>
<ul>
<li>查看对象x的模式：空，数值，字符，逻辑，复数，列表，函数(NULL，numeric，character，logical，complex，list，function)。</li>
</ul>
</blockquote>
<blockquote>
<p>class(x)</p>
<ul>
<li>查看对象x的类型：除了mode里列出的几种类型外，还有整数，矩阵，因子，阵列，数据框，时间序列(integer，matrix，factor，array，data frame，ts)等其他类型。mode主要用于区别数据存放的方式，而class是一种更细微的分类方式，比如矩阵，就是一种更“有序”的数据存放方式。此命令比mode常用。</li>
</ul>
</blockquote>
<blockquote>
<p>as.matrix(x)</p>
<ul>
<li>把对象x转为矩阵型。</li>
</ul>
</blockquote>
<blockquote>
<p>as.numeric(x)</p>
<ul>
<li>把对象x转为数值型。</li>
</ul>
</blockquote>
<blockquote>
<p>str(x)</p>
<ul>
<li>查看对象x的结构。str是structure的缩写。</li>
</ul>
</blockquote>
<blockquote>
<p>rm(x)</p>
<ul>
<li>移除对象x。</li>
</ul>
</blockquote>
<blockquote>
<p>rm(list=ls(all=TRUE))</p>
<ul>
<li>移除所有对象。</li>
</ul>
</blockquote>
<hr>
<h1 id="与向量有关的基本操作"><a href="#与向量有关的基本操作" class="headerlink" title="与向量有关的基本操作"></a>与向量有关的基本操作</h1><blockquote>
<p>x = c(1,2,4)</p>
<ul>
<li>生成元素依次为1,2,4的向量x，这里的c是concatenate的意思。注意其类型是数值，不是矩阵。</li>
</ul>
</blockquote>
<blockquote>
<p>x = c(“a”,”b”,”cd”)</p>
<ul>
<li>生成元素依次为”a”,”b”,”cd”的字符向量x。</li>
</ul>
</blockquote>
<blockquote>
<p>x = paste(“a”,”b”,”cd”)</p>
<ul>
<li>生成”a b cd”的字符x。</li>
</ul>
</blockquote>
<blockquote>
<p>x[a:b]</p>
<ul>
<li>向量x的第a到b个元素。</li>
</ul>
</blockquote>
<blockquote>
<p>x[-i]</p>
<ul>
<li>剔除向量x第i个元素所得的向量。</li>
</ul>
</blockquote>
<blockquote>
<p>length(x)</p>
<ul>
<li>向量x的长度。</li>
</ul>
</blockquote>
<blockquote>
<p>x = seq(a, b, length = n)</p>
<ul>
<li>生成以一个n维数值型向量x，第一个元素为a，最后一个元素为b，中间元素依次等距递增。(假设a&lt;b)</li>
</ul>
</blockquote>
<blockquote>
<p>x = seq(a, b, c)</p>
<ul>
<li>生成一个数值型向量x，第一个元素为a，其后元素依次加c，直到最后一个元素加c大于b。(假设a&lt;b)</li>
</ul>
</blockquote>
<blockquote>
<p>x = seq(a)</p>
<ul>
<li>从1开始生成一个递增或递减数值型向量x，最后一个元素绝对值为小于等于|a|的最大整数。</li>
</ul>
</blockquote>
<blockquote>
<p>x = a:b</p>
<ul>
<li>生成一个从a递增(减)到b的数值型向量x。(a和b都是整数)</li>
</ul>
</blockquote>
<blockquote>
<p>x = rep(v, n)</p>
<ul>
<li>对向量v进行n次复制生成新的向量x。</li>
</ul>
</blockquote>
<blockquote>
<p>x = rep(v, each = n)</p>
<ul>
<li>依次对向量v的每个元素复制n此生成新的向量x。</li>
</ul>
</blockquote>
<blockquote>
<p>x = round(v)</p>
<ul>
<li>生成一个向量x，其中每个元素是v对应元素的最近整数。</li>
</ul>
</blockquote>
<blockquote>
<p>order(x)</p>
<ul>
<li>获得向量x第i大元素在向量中的位置。</li>
</ul>
</blockquote>
<blockquote>
<p>rank(x)</p>
<ul>
<li>获得向量x每个元素大小位置。</li>
</ul>
</blockquote>
<blockquote>
<p>sort(x)</p>
<ul>
<li>对向量x从小到大进行排序。降序：sort(x, decreasing = TRUE)。</li>
</ul>
</blockquote>
<blockquote>
<p>tapply(x,f,g)</p>
<ul>
<li>根据因子f对向量x分类执行函数g。</li>
</ul>
</blockquote>
<blockquote>
<p>split(x,f)</p>
<ul>
<li>向量x按因子f分类。</li>
</ul>
</blockquote>
<blockquote>
<p>diff(x)</p>
<ul>
<li>返回向量x的差分向量。</li>
</ul>
</blockquote>
<blockquote>
<p>cumsum(x)</p>
<ul>
<li>返回向量x的累加向量。</li>
</ul>
</blockquote>
<hr>
<h1 id="与矩阵有关的基本操作"><a href="#与矩阵有关的基本操作" class="headerlink" title="与矩阵有关的基本操作"></a>与矩阵有关的基本操作</h1><hr>
<blockquote>
<p>M = matrix(0,c(m,n))</p>
<ul>
<li>生成m行n列的0矩阵。</li>
</ul>
</blockquote>
<blockquote>
<p>M = rbind(X,Y)</p>
<ul>
<li>按行合并矩阵X和Y形成新矩阵M。(X和Y列数需相同）</li>
</ul>
</blockquote>
<blockquote>
<p>M = cbind(X,Y)</p>
<ul>
<li>按列合并矩阵X和Y形成新矩阵M。(X和Y行数需相同）</li>
</ul>
</blockquote>
<blockquote>
<p>colnames(M)</p>
<ul>
<li>矩阵M的列名。</li>
</ul>
</blockquote>
<blockquote>
<p>rownames(M)</p>
<ul>
<li>矩阵M的行名。</li>
</ul>
</blockquote>
<blockquote>
<p>nrow(M)</p>
<ul>
<li>矩阵M的行数。</li>
</ul>
</blockquote>
<blockquote>
<p>ncol(M)</p>
<ul>
<li>矩阵M的列数。</li>
</ul>
</blockquote>
<blockquote>
<p>diag(M)</p>
<ul>
<li>矩阵M的对角线元素形成的向量</li>
</ul>
</blockquote>
<blockquote>
<p>M = diag(x)</p>
<ul>
<li>生成以向量x为对角线元素，其他位置元素为0的矩阵M。</li>
</ul>
</blockquote>
<blockquote>
<p>dim(M)</p>
<ul>
<li>矩阵M的维度。</li>
</ul>
</blockquote>
<blockquote>
<p>M[i,]</p>
<ul>
<li>矩阵M第i行。(数值型)</li>
</ul>
</blockquote>
<blockquote>
<p>M[i,,drop = FALSE]</p>
<ul>
<li>矩阵M第i行。(矩阵型)</li>
</ul>
</blockquote>
<blockquote>
<p>M = M[-i,]<br>lo9.-  删除矩阵M第i行。</p>
</blockquote>
<blockquote>
<p>M[,j]</p>
<ul>
<li>矩阵M第j列。</li>
</ul>
</blockquote>
<blockquote>
<p>M[i,j]</p>
<ul>
<li>矩阵M第i行j列元素。</li>
</ul>
</blockquote>
<blockquote>
<p>t(M)</p>
<ul>
<li>矩阵M的转置。若M为数值型向量，则t(M)为矩阵型行向量。</li>
</ul>
</blockquote>
<blockquote>
<p>X%*%Y</p>
<ul>
<li>矩阵X乘矩阵Y。若Y是数值型的向量，R会自动判断其为行向量还是列向量。若X与Y为维度匹配的数值型向量，则返回的是矩阵型向量的内积。</li>
</ul>
</blockquote>
<blockquote>
<p>x%o%y</p>
<ul>
<li>数值型向量x与y的外积(矩阵型)。</li>
</ul>
</blockquote>
<blockquote>
<p>X*Y</p>
<ul>
<li>矩阵X与矩阵Y的Hadamard乘积。加、减、除、求余的规则和乘相同，即相同位置的元素进行运算。</li>
</ul>
</blockquote>
<blockquote>
<p>eigen(M)$val<br>eigen(M)$vec</p>
<ul>
<li>求矩阵M的特征值和特征向量。</li>
</ul>
</blockquote>
<blockquote>
<p>solve(M)</p>
<ul>
<li>矩阵M求逆。</li>
</ul>
</blockquote>
<blockquote>
<p>solve(A,b)</p>
<ul>
<li>求解线性方程Ax=b。</li>
</ul>
</blockquote>
<blockquote>
<p>apply(M, dimcode, f, fargs)</p>
<ul>
<li>对矩阵M的行(dimcode=1)或列(dimcode=2)依次进行函数f操作，f的变量(arguments)方正fargs里。</li>
</ul>
</blockquote>
<hr>
<h1 id="与列表有关的基本操作"><a href="#与列表有关的基本操作" class="headerlink" title="与列表有关的基本操作"></a>与列表有关的基本操作</h1><blockquote>
<p>L = list(a = , b = , c = ,…)</p>
<ul>
<li>建立列表L。</li>
</ul>
</blockquote>
<blockquote>
<p>L$a<br>L[[a]]</p>
<ul>
<li>返回列表L里的对象a。</li>
</ul>
</blockquote>
<blockquote>
<p>L$a = NULL</p>
<ul>
<li>去除列表L里的对象a。</li>
</ul>
</blockquote>
<blockquote>
<p>names(L)</p>
<ul>
<li>列出列表L里的对象名。</li>
</ul>
</blockquote>
<blockquote>
<p>unname(L)</p>
<ul>
<li>去掉列表L里的对象名。</li>
</ul>
</blockquote>
<blockquote>
<p>lapply(…)</p>
<ul>
<li>list apply。功能与apply类似(参考上面的apply)，用于列表型数据。</li>
</ul>
</blockquote>
<blockquote>
<p>sapply(…)</p>
<ul>
<li>simplified apply。功能与lapply类似，区别在于函数结果的类型不是列表(list)。</li>
</ul>
</blockquote>
<hr>
<h1 id="与数据框有关的基本操作"><a href="#与数据框有关的基本操作" class="headerlink" title="与数据框有关的基本操作"></a>与数据框有关的基本操作</h1><ul>
<li>数据框是一种特殊的列表，所以对列表适用的函数往往对数据框也适用。此外，数据框也有矩阵型数据的特征，所以一些适用于矩阵型数据的函数，不如rbind，cbind，apply等也可以作用在数据框上。</li>
</ul>
<blockquote>
<p>Data = data.frame(…)</p>
<ul>
<li>创建数据框Data。</li>
</ul>
</blockquote>
<blockquote>
<p>fix(Data)</p>
<ul>
<li>编辑数据框Data。</li>
</ul>
</blockquote>
<blockquote>
<p>head(Data)</p>
<ul>
<li>显示数据框Data的前几行。</li>
</ul>
</blockquote>
<blockquote>
<p>attribute(Data)</p>
<ul>
<li>列出数据框Data的组成部分。</li>
</ul>
</blockquote>
<blockquote>
<p>names(Data)</p>
<ul>
<li>显示数据框Data的变量名。</li>
</ul>
</blockquote>
<blockquote>
<p>row.names(Data)</p>
<ul>
<li>显示数据框Data的行名。</li>
</ul>
</blockquote>
<blockquote>
<p>Data$name1</p>
<ul>
<li>数据框Data中名为name1的变量。</li>
</ul>
</blockquote>
<blockquote>
<p>Data[i]</p>
<ul>
<li>数据框Data中第i个变量形成的数据框。</li>
</ul>
</blockquote>
<blockquote>
<p>merge(D1,D2)</p>
<ul>
<li>合并数据框D1和D2，需要D1和D2中有至少一个相同的变量。</li>
</ul>
</blockquote>
<hr>
<h1 id="与逻辑型数据有关的基本操作"><a href="#与逻辑型数据有关的基本操作" class="headerlink" title="与逻辑型数据有关的基本操作"></a>与逻辑型数据有关的基本操作</h1><hr>
<blockquote>
<p>is.data.frame(x)</p>
<ul>
<li>判断是否对象x是数据框。类似命令有is.ts(x)，is.numeric(x)等。</li>
</ul>
</blockquote>
<blockquote>
<p>all(x&gt;a)</p>
<ul>
<li>判断是否对象x的每个元素都大于a。</li>
</ul>
</blockquote>
<blockquote>
<p>any(x&gt;a)</p>
<ul>
<li>判断对象x的元素中是否存在一个大于a。</li>
</ul>
</blockquote>
<blockquote>
<p>x&gt;y</p>
<ul>
<li>判断x的每个元素是否大于y的每个元素。</li>
</ul>
</blockquote>
<blockquote>
<p>x[x&gt;a]</p>
<ul>
<li>向量x中大于a的元素组成的新向量。</li>
</ul>
</blockquote>
<blockquote>
<p>subset(x, x&gt;a)</p>
<ul>
<li>向量x中大于a的元素组成的新向量。与上面例子的区别在于若向量元素里有NA，上面的例子会保留在结果中，而subset命令会剔除掉。</li>
</ul>
</blockquote>
<blockquote>
<p>which(x, x&gt;a)</p>
<ul>
<li>返回向量中大于a的元素的位置。</li>
</ul>
</blockquote>
<blockquote>
<p>x = ifelse(b, u, v)</p>
<ul>
<li>生成一个与b(逻辑向量)维度相同的数值向量，若b[i]为TRUE，则x[i]为u，反之为v。</li>
</ul>
</blockquote>

            </div>
            <hr>

            

            <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">

<div id="article-share">
    
    <div class="social-share" data-disabled="qzone" data-wechat-qrcode-helper="<p>微信里点“发现”->“扫一扫”二维码便可查看分享。</p>"></div>
    
</div>

<script src="/libs/share/js/social-share.min.js"></script>

            <div class="reprint">
                <p>
                    <span class="reprint-tip">转载请注明: </span>
                    <a href="https://xuanshan.gitee.io" class="b-link-green">炫杉</a>
                    <i class="fa fa-angle-right fa-lg fa-fw text-color"></i>
                    <a href="/Others/R学习记录/" class="b-link-green">R常用命令</a>
                </p>
            </div>
        </div>
    </div>

    

    

    

    
    <div class="livere-card card" data-aos="fade-up">
    <!-- 来必力City版安装代码 -->
    <div id="lv-container" class="card-content" data-id="city" data-uid="MTAyMC8yOTg2My82NDI5">
        <script type="text/javascript">
            (function (d, s) {
                let j, e = d.getElementsByTagName(s)[0];
                if (typeof LivereTower === 'function') {
                    return;
                }

                j = d.createElement(s);
                j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
                j.async = true;

                e.parentNode.insertBefore(j, e);
            })(document, 'script');
        </script>
        <noscript>为正常使用来必力评论功能请激活JavaScript。</noscript>
    </div>
    <!-- City版安装代码已完成 -->
</div>
    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">上一篇</div>
            <div class="card">
                <a href="/iOS/iOS布局问题/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/17.jpg" class="responsive-img" alt="iOS布局问题入门">
                        
                        <span class="card-title">iOS布局问题入门</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary">昨天重拾iOS发现，怎么加Constraints等设计Layout的问题全忘了。赶紧复习一下。

Alignment 居中这两个√解决
AutoLayout 自动布局注意。边界要选Safe Area。
Stack View选中多个组件。点击</div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="fa fa-clock-o fa-fw icon-date"></i>2018-04-01
                        </span>
                        <span class="publish-author">
                            
                            <i class="fa fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/iOS/" class="post-category" target="_blank">
                                    iOS
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/Swift/" target="_blank">
                        <span class="chip bg-color">Swift</span>
                    </a>
                    
                    <a href="/tags/Design/" target="_blank">
                        <span class="chip bg-color">Design</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">下一篇</div>
            <div class="card">
                <a href="/iOS/SwiftDemo1/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/5.jpg" class="responsive-img" alt="Swift Demo1 秒表">
                        
                        <span class="card-title">Swift Demo1 秒表</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary">这是阅读项目30Days of Swift源码的仿写记录，该项目受到国外一个教程：Swift100天的启发。

Demo 1 StopWatch第一个小demo是个秒表。功能简单就是点击Play计时。Pause暂停。Reset重置。
载入设</div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="fa fa-clock-o fa-fw icon-date"></i>2018-03-31
                            </span>
                        <span class="publish-author">
                            
                            <i class="fa fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/iOS/" class="post-category" target="_blank">
                                    iOS
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/Demo/" target="_blank">
                        <span class="chip bg-color">Demo</span>
                    </a>
                    
                    <a href="/tags/Swift/" target="_blank">
                        <span class="chip bg-color">Swift</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>
</div>
    </div>
    <div class="col l3 hide-on-med-and-down">
        <div class="toc-widget">
            <div class="toc-title">目录</div>
            <div id="toc-content">

            </div>
        </div>
    </div>
</div>

<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingSelector: 'h1,h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h1,h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });
    });
</script>
    

</main>

<footer class="page-footer bg-color">
    <div class="container row center-align">
        <div class="col s12 m8 l8 copy-right">
            &copy;<a href="https://o--o.win" target="_blank">炫杉2018</a> 
            <a href="https://hexo.io/" target="_blank">Hexo</a> 强力驱动
              主题 <a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">matery</a>        </div>
        <div class="col s12 m4 l4 social-link"><a href="https://github.com/ixsim" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
    <i class="fa fa-github"></i>
</a>

<a href="mailto:chenjiayin1990@163.com" class="tooltipped" target="_blank" data-tooltip="邮件:chinalixs@qq.com" data-position="top" data-delay="50">
    <i class="fa fa-envelope-open"></i>
</a>

<a href="http://wpa.qq.com/msgrd?v=3&uin=6956820&site=qq&menu=yes" class="tooltipped" data-tooltip="QQ: 6956820" data-position="top" data-delay="50">
    <i class="fa fa-qq"></i>
</a>
</div>
    </div>
</footer>

<div class="progress-bar"></div>


<!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title">搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字" class="search-input" autofocus>
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script src="/js/search.js"></script>
<script type="text/javascript">
    searchFunc("/" + "search.xml", 'searchInput', 'searchResult');
</script>
<!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fa fa-angle-up"></i>
    </a>
</div>


<script src="/libs/materialize/js/materialize.min.js"></script>
<script src="/libs/masonry/masonry.pkgd.min.js"></script>
<script src="/libs/aos/aos.js"></script>
<script src="/libs/scrollprogress/scrollProgress.min.js"></script>
<script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
<script src="/js/matery.js"></script>
</body>
</html>